package cc.messcat.web.filter;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.Set;
import java.util.TimeZone;

import org.json.JSONObject;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

import cc.messcat.entity.filter.FilterFilterOutAllExcept;
import cc.messcat.entity.filter.FilterSerializeAllExcept;
import cc.messcat.entity.fupin.PoorFamily;
import cc.messcat.entity.fupin.VisitRecd;

public class JsonFilter {

	
	/*public String jsonSyChannelinfoFilter(Object obj){
		try {
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")).setTimeZone(TimeZone.getTimeZone("GMT+8"));
			Set<String> set = new HashSet<String>();
			set.add("syPlayInfos");
			Set<String> set2 = new HashSet<String>();
			set2.add("id");
			set2.add("name");
			set2.add("username");
			set2.add("edittor");
			set2.add("creater");
		    
		    FilterProvider filters = new SimpleFilterProvider().addFilter("jsonSerializeAllExceptFilter",SimpleBeanPropertyFilter.serializeAllExcept(set))
		    		.addFilter("jsonFilterOutAllExceptFilter",SimpleBeanPropertyFilter.filterOutAllExcept(set2));  
		    objectMapper.addMixIn(SyChannelinfo.class,FilterSerializeAllExcept.class);
		    objectMapper.addMixIn(NtAuthorities.class,FilterFilterOutAllExcept.class);
		    objectMapper.addMixIn(McUser.class,FilterFilterOutAllExcept.class);
		    String jsonStr = objectMapper.writer(filters).writeValueAsString(obj);  
		    
		    return jsonStr;
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return "";
	}*/
	/**
	 * 走访记录数据分页
	 * @param obj
	 * @return
	 * @throws IOException 
	 */
	public Object jsonVisitRecdPagerFilter(Object obj) throws IOException {
		try {
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"))
					.setTimeZone(TimeZone.getTimeZone("GMT+8"));
			Set<String> set = new HashSet<String>();
			Set<String> set2 = new HashSet<String>();
			
			set2.add("visitRecd");
			set2.add("id");
			set2.add("addTime");//走访时间
			set2.add("target");//走访目的
			set2.add("content");//走访描述

			set2.add("poorFamily");
			set2.add("id");//走访贫困户ID
			set2.add("number");//走访贫困户户编号
	
			
			
			
		    FilterProvider filters = new SimpleFilterProvider().addFilter("jsonSerializeAllExceptFilter",SimpleBeanPropertyFilter.serializeAllExcept(set))
		    		.addFilter("jsonFilterOutAllExceptFilter",SimpleBeanPropertyFilter.filterOutAllExcept(set2));  
			objectMapper.addMixIn(VisitRecd.class, FilterFilterOutAllExcept.class);
			objectMapper.addMixIn(PoorFamily.class, FilterFilterOutAllExcept.class);
			String jsonStr = objectMapper.writer(filters).writeValueAsString(obj);
			Object object = objectMapper.readValue(jsonStr, Object.class);
			return object;
 
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return "";

	}
	
	/**
	 * 走访记录详情数据
	 * @param obj
	 * @return
	 * @throws IOException 
	 */
	public Object jsonVisitRecdIdFilter(Object obj) throws IOException {
		try {
			ObjectMapper objectMapper = new ObjectMapper();
			objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"))
					.setTimeZone(TimeZone.getTimeZone("GMT+8"));
			Set<String> set = new HashSet<String>();
			Set<String> set2 = new HashSet<String>();
			
			set2.add("visitRecd");
			set2.add("id");
			set2.add("addTime");//走访时间
			set2.add("target");//走访目的
			set2.add("content");//走访描述
			set2.add("remarks");//走访备注
			set2.add("accessoryUrl");//附件url ,号隔开
			
			set2.add("poorFamily");
			set2.add("id");//走访贫困户ID
			set2.add("number");//走访贫困户户编号
			
			
		    FilterProvider filters = new SimpleFilterProvider().addFilter("jsonSerializeAllExceptFilter",SimpleBeanPropertyFilter.serializeAllExcept(set))
		    		.addFilter("jsonFilterOutAllExceptFilter",SimpleBeanPropertyFilter.filterOutAllExcept(set2));  
			objectMapper.addMixIn(VisitRecd.class, FilterFilterOutAllExcept.class);
			objectMapper.addMixIn(PoorFamily.class, FilterFilterOutAllExcept.class);
			String jsonStr = objectMapper.writer(filters).writeValueAsString(obj);
			Object object = objectMapper.readValue(jsonStr, Object.class);
			return object;
 
		} catch (JsonProcessingException e) {
			e.printStackTrace();
		}
		return "";

	}
	
}
